<template>
  <div class="create-form">
    <el-form ref="form" :model="form" class="for-create">
      <el-form-item class="form-item">
        <lable class="form-item-one">会议名称</lable>
        <div class="form-item-two">
        <el-input v-model="form.name"></el-input>
        </div>
      </el-form-item>
      <!--<el-form-item class="form-item">-->
        <!--<lable class="form-item-one">会议性质</lable>-->
        <!--<div class="form-item-two">-->
        <!--<el-select v-model="form.region" placeholder="请选择会议性质">-->
          <!--<el-option label="发布会" value="shanghai"></el-option>-->
          <!--<el-option label="企业内部会议" value="beijing"></el-option>-->
        <!--</el-select>-->
        <!--</div>-->
      <!--</el-form-item>-->
      <el-form-item  class="form-item">
        <lable class="form-item-one">会议上限人数</lable>
        <div class="form-item-two">
        <el-input-number v-model="num1" @change="handleChange" :min="1"  label="描述文字"></el-input-number>
        </div>
      </el-form-item>
      <!--<el-form-item  class="form-item">-->
        <!--<lable class="form-item-one">开始时间</lable>-->
        <!--<div class="form-item-two">-->
        <!--<el-col :span="11">-->
          <!--<el-date-picker type="date" placeholder="选择日期" v-model="form.date1" style="width: 100%;"></el-date-picker>-->
        <!--</el-col>-->
        <!--<el-col class="line" :span="2">-</el-col>-->
        <!--<el-col :span="11">-->
          <!--<el-time-picker type="fixed-time" placeholder="选择时间" v-model="form.date2" style="width: 100%;"></el-time-picker>-->
        <!--</el-col>-->
      <!--</div>-->
      <!--</el-form-item>-->
      <!--<el-form-item  class="form-item">-->
        <!--<lable class="form-item-one">结束时间</lable>-->
        <!--<div class="form-item-two">-->
        <!--<el-col :span="11">-->
          <!--<el-date-picker type="date" placeholder="选择日期" v-model="form.date1" style="width: 100%;"></el-date-picker>-->
        <!--</el-col>-->
        <!--<el-col class="line" :span="2">-</el-col>-->
        <!--<el-col :span="11">-->
          <!--<el-time-picker type="fixed-time" placeholder="选择时间" v-model="form.date2" style="width: 100%;"></el-time-picker>-->
        <!--</el-col>-->
        <!--</div>-->
      <!--</el-form-item>-->
      <el-form-item  >
        <lable class="form-item-one">是否创建密码</lable>
        <div class="form-item-two">
        <el-switch v-model="form.delivery" @change="handleSwitch($event,form.delivery)" active-value="100" inactive-value="0"></el-switch>
        </div>
      </el-form-item>
      <div class="anniu">
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button @click="exitcancle">取消</el-button>
      </div>
      <el-dialog title="请输入密码" :visible.sync="dialogFormVisible">
        <el-form :model="form">
          <el-form-item label="房间密码" :label-width="formLabelWidth">
            <el-input v-model="form.pwd" autocomplete="off" type="password"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="cancledialogFormVisible()">取 消</el-button>
          <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
        </div>
      </el-dialog>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'createroom',
  data () {
    return {
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: '0',
        type: [],
        resource: '',
        desc: '',
        pwd: ''
      },
      dialogFormVisible: false,
      num1: 5
    }
  },
  methods: {
    handleSwitch (val, flag) {
      if (flag === '100') {
        this.dialogFormVisible = true
      }
    },
    cancledialogFormVisible () {
      this.dialogFormVisible = false
      this.form.delivery = '0'
    },
    onSubmit () {
      this.$axios.post("/api/room/createRoom",{
        roomName:this.form.name,
        roomLimit:this.num1,
        roomPassword:this.form.pwd
      }).then(res=>{
          if (res.data.code==1){
            let list = JSON.parse(sessionStorage.getItem("roomIdList"))
            list.push(res.data.roomId)
            sessionStorage.setItem("roomIdList",JSON.stringify(list))
            this.$message({
              message: '创建成功',
              type: 'success',
              duration:3000,
            })
            this.$router.push({ path:'/index'});
          }
      })
    },
    exitcancle () {
      this.$router.push('/index')
    }
  }
}
</script>

<style scoped>
.create-form{
  height: 100%;
}
  .for-create{
    height: 100%;
    margin: .2rem;
  }
  .form-item{
    display: flow;
    margin: .2rem auto;
  }
  .form-item-one{
    float: left;
    width: 30%;
    text-align: center;
  }
  .form-item-two{
    float: right;
    width: 70%;
    text-align: center;
  }
  .anniu{
    display:flex;
    justify-content:center;
    align-items:center;
  }
</style>
